<template>
  <!--列表-->
  <div class="list-container">
    <div class="sortList clearfix">
      <!-- 加 v-if来判断 state中数据的长度 : 常用 -->
      <!-- v-if="$store.state.home.swiperList.length" -->
      <!-- 如果有长度,则展示下面的div,如果没有长度,则不展示 -->
      <div class="center">
        <!-- 获取整个轮播图数据 -->
        <!-- <p>{{ $store.state.home.swiperList }}</p> -->
        <!-- <p v-for="item in $store.state.home.swiperList" :key="item.id">
          {{ item.imgUrl }}
        </p> -->
        <!--banner轮播-->
        <div class="swiper-container" id="mySwiper" v-if="swiperList.length">
          <!-- <div class="swiper-slide" v-for="item in swiperList" :key="item.id">
              <img :src="item.imgUrl" />
            </div> -->
          <swiper class="swiper" :options="swiperOption">
            <swiper-slide v-for="item in swiperList" :key="item.id">
              <img :src="item.imgUrl" alt="" />
            </swiper-slide>
            <!-- 展示轮播图下方的小圆点 -->

            <div class="swiper-pagination" slot="pagination"></div>
            <!-- 展示左右两边的切换箭头 -->

            <div class="swiper-button-prev" slot="button-prev"></div>
            <div class="swiper-button-next" slot="button-next"></div>
          </swiper>
        </div>
      </div>
      <div class="right">
        <div class="news">
          <h4>
            <em class="fl">尚品汇快报</em>
            <span class="fr tip">更多 ></span>
          </h4>
          <div class="clearix"></div>
          <ul class="news-list unstyled">
            <li><span class="bold">[特惠]</span>备战开学季 全民半价购数码</li>
            <li><span class="bold">[公告]</span>备战开学季 全民半价购数码</li>
            <li><span class="bold">[特惠]</span>备战开学季 全民半价购数码</li>
            <li><span class="bold">[公告]</span>备战开学季 全民半价购数码</li>
            <li><span class="bold">[特惠]</span>备战开学季 全民半价购数码</li>
          </ul>
        </div>
        <ul class="lifeservices">
          <li class="life-item">
            <i class="list-item"></i>
            <span class="service-intro">话费</span>
          </li>
          <li class="life-item">
            <i class="list-item"></i>
            <span class="service-intro">机票</span>
          </li>
          <li class="life-item">
            <i class="list-item"></i>
            <span class="service-intro">电影票</span>
          </li>
          <li class="life-item">
            <i class="list-item"></i>
            <span class="service-intro">游戏</span>
          </li>
          <li class="life-item">
            <i class="list-item"></i>
            <span class="service-intro">彩票</span>
          </li>
          <li class="life-item">
            <i class="list-item"></i>
            <span class="service-intro">加油站</span>
          </li>
          <li class="life-item">
            <i class="list-item"></i>
            <span class="service-intro">酒店</span>
          </li>
          <li class="life-item">
            <i class="list-item"></i>
            <span class="service-intro">火车票</span>
          </li>
          <li class="life-item">
            <i class="list-item"></i>
            <span class="service-intro">众筹</span>
          </li>
          <li class="life-item">
            <i class="list-item"></i>
            <span class="service-intro">理财</span>
          </li>
          <li class="life-item">
            <i class="list-item"></i>
            <span class="service-intro">礼品卡</span>
          </li>
          <li class="life-item">
            <i class="list-item"></i>
            <span class="service-intro">白条</span>
          </li>
        </ul>
        <div class="ads">
          <img src="./images/ad1.png" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// 导入辅助函数
import { mapActions, mapState } from 'vuex'
// 导入组件
import { Swiper, SwiperSlide } from 'vue-awesome-swiper'
// 导入swiper 相关css样式
import 'swiper/css/swiper.css'
export default {
  data() {
    return {
      // Swiper 组件的配置项，通过 props 的方式传递给 Swiper 组件
      // Swiper 组件接收到这些配置项，就能够按照配置项展示轮播图
      // 多翻阅 swiper 的官方文档
      swiperOption: {
        slidesPerView: 1, // 一屏展示几张 轮播图,假设是2 就是一个屏幕展示两张轮播图
        spaceBetween: 30, // 每张轮播图之间的间隙
        loop: true, // 轮播图是否采用 无线循环模式,就是到最后一张再滑动就展示第一张
        autoplay: true, // 是否自动播放,也可以将值写成一个对象

        // autoplay: {
        //   delay: 1000 // 设置当前轮播图自动播放(按照一秒一切换)
        // },
        // 对轮播图小圆点指示器进行配置
        pagination: {
          el: '.swiper-pagination', // 就将小圆点指示器放到哪一个元素中
          clickable: true // 点击小圆点是否能切换轮播图
        },

        // 设置上一张、下一张对应的容器元素是谁
        navigation: {
          nextEl: '.swiper-button-next',
          prevEl: '.swiper-button-prev'
        }
      }
    }
  },
  name: 'ListEl',
  // 将组件注册
  components: {
    Swiper,
    SwiperSlide
  },
  created() {
    // 通过 dispatch 调用 actions
    // this.$store.dispatch('home/getSwiprData')

    this.getSwiprData()
  },
  methods: {
    // 通过辅助函数来调用 模块中的方法
    ...mapActions('home', ['getSwiprData'])
  },
  computed: {
    ...mapState('home', ['swiperList'])
  }
}
</script>

<style lang="less" scoped>
.list-container {
  width: 1200px;
  margin: 0 auto;

  .sortList {
    height: 464px;
    padding-left: 210px;

    .center {
      box-sizing: border-box;
      width: 740px;
      height: 100%;
      padding: 5px;
      float: left;
    }

    .right {
      float: left;
      width: 250px;

      .news {
        border: 1px solid #e4e4e4;
        margin-top: 5px;

        h4 {
          border-bottom: 1px solid #e4e4e4;
          padding: 5px 10px;
          margin: 5px 5px 0;
          line-height: 22px;
          overflow: hidden;
          font-size: 14px;

          .fl {
            float: left;
          }

          .fr {
            float: right;
            font-size: 12px;
            font-weight: 400;
          }
        }

        .news-list {
          padding: 5px 15px;
          line-height: 26px;

          .bold {
            font-weight: 700;
          }
        }
      }

      .lifeservices {
        border-right: 1px solid #e4e4e4;
        overflow: hidden;
        display: flex;
        flex-wrap: wrap;

        .life-item {
          border-left: 1px solid #e4e4e4;
          border-bottom: 1px solid #e4e4e4;
          margin-right: -1px;
          height: 64px;
          text-align: center;
          position: relative;
          cursor: pointer;
          width: 25%;

          .list-item {
            background-image: url(./images/icons.png);
            width: 61px;
            height: 40px;
            display: block;
          }

          .service-intro {
            line-height: 22px;
            width: 60px;
            display: block;
          }

          &:nth-child(1) {
            .list-item {
              background-position: 0px -5px;
            }
          }

          &:nth-child(2) {
            .list-item {
              background-position: -62px -5px;
            }
          }

          &:nth-child(3) {
            .list-item {
              background-position: -126px -5px;
            }
          }

          &:nth-child(4) {
            .list-item {
              background-position: -190px -5px;
            }
          }

          &:nth-child(5) {
            .list-item {
              background-position: 0px -76px;
            }
          }

          &:nth-child(6) {
            .list-item {
              background-position: -62px -76px;
            }
          }

          &:nth-child(7) {
            .list-item {
              background-position: -126px -76px;
            }
          }

          &:nth-child(8) {
            .list-item {
              background-position: -190px -76px;
            }
          }

          &:nth-child(9) {
            .list-item {
              background-position: 0px -146px;
            }
          }

          &:nth-child(10) {
            .list-item {
              background-position: -62px -146px;
            }
          }

          &:nth-child(11) {
            .list-item {
              background-position: -126px -146px;
            }
          }

          &:nth-child(12) {
            .list-item {
              background-position: -190px -146px;
            }
          }
        }
      }

      .ads {
        margin-top: 5px;

        img {
          opacity: 0.8;
          transition: all 400ms;

          &:hover {
            opacity: 1;
          }
        }
      }
    }
  }
}
</style>
